package com.kxf.androidtestdemo.fragments;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.kxf.androidtestdemo.R;
import com.kxf.utils.Util;

/**
 * @ProjectName: AndroidTestDemo
 * @Package: com.kxf.androidtestdemo.fragments
 * @ClassName: BaseFragment
 * @Description: java类作用描述
 * @Author: kuangxuefeng
 * @qq: 1024883177
 * @CreateDate: 2020/12/1 16:19
 */
public abstract class BaseFragment extends Fragment {
    protected String TAG;
    protected View rootView = null;

    protected abstract @LayoutRes int getLayoutRes();

    protected abstract void initView();

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        TAG = this.getClass().getName();
        Log.i(TAG, "onCreate====>>>>>");
    }

    @Nullable
    @Override
    public final View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        Log.i(TAG, "onCreateView====>>>>>");
        @LayoutRes int layoutId = getLayoutRes();
        if (layoutId != 0) {
            rootView = inflater.inflate(layoutId, container, false);
        }
        initView();
        return rootView;
    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        Log.i(TAG, "onHiddenChanged====>>>>>" + hidden);
    }

    @Override
    public void onResume() {
        super.onResume();
        Log.i(TAG, "onResume====>>>>>");
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        Log.i(TAG, "setUserVisibleHint====>>>>>" + isVisibleToUser);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Log.i(TAG, "BaseFragment onActivityResult " + requestCode+ " " + resultCode+ " ==>>>" + Util.getIntentExtrasToString(data));
    }
}
